package cn.icesky1stm.isblog.advice;

import cn.icesky1stm.isblog.exception.IsBlogException;
import cn.icesky1stm.isblog.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName: IsBlogExceptionAdvice <br>
 * @Description: 定义统一异常处理 <br>
 * @Package: cn.icesky1stm.isblog.advice <br>
 * @author: suitianmou <br>
 * @Date: 2021/6/27-20:36 <br>
 * @version: 1.0 <br>
 * @see <br>
 * @since (从产品的哪一个版本此类被添加进来 ( 可选))<br>
 * 修改历史: <br>
 * 修改时间             修改人           版本变更           修改说明<br>
 * -----------------------------------------------------<br>
 * <br>
 */
@ControllerAdvice
@Slf4j
public class IsBlogExceptionAdvice {
    /**
     * 统一处理IsBlogExecepion
     */

    @ExceptionHandler(IsBlogException.class)
    @ResponseBody
    public Result<Object> exceptionHandler(IsBlogException exception){
        log.error("统一异常处理：", exception);
        return new Result<>(exception.getErrorCode(), exception.getMessage());
    }
}
